package com.fc.mall.portal.task;

import com.fc.mall.portal.service.UmsMemberService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Configuration
@EnableScheduling
public class MemberLockStatusTask
{
    private static Logger LOGGER =LoggerFactory.getLogger(MemberLockStatusTask.class);

    private boolean running = false;

    @Autowired
    private UmsMemberService memberService;


//    @Scheduled(cron = "0/5 * * * * ?")
    //或直接指定时间间隔，例如：10分钟
    @Scheduled(fixedRate=10*60*1000)
    private void configureTasks()
    {
        try
        {
            System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
            if (running)
            {
                return;
            }
            running = true;

            memberService.resetMemberLockStatus();
            memberService.recoveryExpiredCoupon();
        }
        catch (Exception e)
        {
            LOGGER.error("MemberLockStatusTask", e.getMessage());
        }
        finally
        {
            running = false;
        }
    }
}
